package chuangyi.com.org.DOMIHome.Utils;

import android.databinding.BindingConversion;

import java.util.Calendar;
import java.util.Date;

/**
 * Created by zxh on 16/11/17.
 */

public class Conversion {
    @BindingConversion
    public static String dateToString(Date date){
        if(date == null){
            return "-:- · 发布于-月-";
        }
        return (new java.text.SimpleDateFormat("HH:mm · 发布于M月dd")).format(date);
    }

    @BindingConversion
    public static String dateToString(Calendar date){
        if(date == null){
            return "-:- · 发布于-月-";
        }
        String text = (new java.text.SimpleDateFormat("yyyy年MM月dd日")).format(date.getTime());
        switch (date.get(Calendar.DAY_OF_WEEK)){
            case Calendar.MONDAY:
                return text + " 周一";
            case Calendar.TUESDAY:
                return text + " 周二";
            case Calendar.WEDNESDAY:
                return text + " 周三";
            case Calendar.THURSDAY:
                return text + " 周四";
            case Calendar.FRIDAY:
                return text + " 周五";
            case Calendar.SATURDAY:
                return text + " 周六";
            case Calendar.SUNDAY:
                return text + " 周日";
            default:
                return text;
        }
    }
//    @BindingConversion
//    public static int StringToInt(String value){
//        try {
//            return Integer.valueOf(value);
//        }catch (NumberFormatException ex){
//            return 0;
//        }
//    }
}
